#!/bin/bash
# Here put anything that is needed to start the service.
# Note that currently this is run directly after install
# i.e. 'service apache2 start'
set -e

# This hook needs to be idempotent, so this could be run when homestead is
# already running, when it's running but not monitored by monit, when
# it's stopped but being monitored (so it's about to start), or stopped
# and unmonitored. To cover all these cases, restart homestead, restart monit,
# then finally have monit monitor homestead.  Note that restarting monit can
# fail because init will also restart it when it stops and restarting
# homestead can fail because monit will restart it.
service homestead restart || /usr/bin/true
service homestead-prov restart || /usr/bin/true
service clearwater-monit restart || /usr/bin/true
sleep 1
monit monitor homestead
monit monitor homestead-prov
